package com.bzkj.inventory.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @ClassName InventoryTaskIdGenerator
 * @Description TODO
 * @Author C1309
 * @Date 2025/6/3 14:28
 */
public class InventoryTaskIdGenerator {
    private static final String TASK_PREFIX = "INV_CMP";
    private static final DateTimeFormatter TIME_FORMAT =
            DateTimeFormatter.ofPattern("yyMMddHHmmssSSS");
    private static int counter = 0;

    public static synchronized String generateTaskId() {
        // 组合任务编号：前缀 + 时间戳 + 随机后缀
        String timestamp = LocalDateTime.now().format(TIME_FORMAT);
        int random = ThreadLocalRandom.current().nextInt(100, 1000);

        // 重置计数器（每秒最多10,000个）
        if (counter == 10000) counter = 0;
        return String.format("%s_%s_%d_%d",
                TASK_PREFIX, timestamp, counter++, random);
    }
}